package com.huizluo.module4.UserMessage;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.net.Socket;

public class Client {

    public static void main(String[] args) {
        Socket s = null;
        ObjectOutputStream op =null;
        ObjectInputStream oi = null;
        try {
            s = new Socket("127.0.0.1",8888);
            System.out.println("connected to server");

            UserMessage msg1 = new UserMessage("check",new User("admin","123123"));
            op = new ObjectOutputStream(s.getOutputStream());
            op.writeObject(msg1);

            oi = new ObjectInputStream(s.getInputStream());
            msg1 = (UserMessage) oi.readObject();
            System.out.println(msg1);

            UserMessage msg2 = new UserMessage("check",new User("admin","123456"));
            op = new ObjectOutputStream(s.getOutputStream());
            op.writeObject(msg2);

            oi = new ObjectInputStream(s.getInputStream());
            msg2 = (UserMessage) oi.readObject();
            System.out.println(msg2);

        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }finally {
            if (null != s) {
                try {
                    s.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }

}
